var app =new Vue({
    el:"#container",
    data:{
        id:"",
        empAccount:{},
        positions:[],
        positionId:""
    },
    mounted:function(){
        this.id=getQueryString("id");
        this.empAccountInfo(this.id);
        this.positionInfo();
    },
    methods:{
        empAccountInfo(id){
            let data=new URLSearchParams();
            data.append("id",id);
            axios({
                method:"post",
                url:"yly-api/admin/findEmpAccount",
                data:data,
                headers:{"url":window.location.pathname,"token":localStorage.token}
            }).then(function (res) {
                console.log(res.data);
                if (res.data.code==200){
                    app.empAccount=res.data.data;
                    app.positionId=app.empAccount.positionId;
                }else if (res.data.code==500){
                    location.href="500.html";
                }
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("请先登录!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        updateEmpAccount(){
            let data=new URLSearchParams();
            data.append("id",app.id);
            data.append("positionId",app.positionId);
            data.append("jobNumber",app.empAccount.jobNumber);
            axios({
                method:"post",
                url:"yly-api/admin/updateEmpAccount",
                data:data,
                headers:{"url":window.location.pathname,"token":localStorage.token}
            }).then(function (res) {
                console.log(res.data);
                if (res.data.code==200){
                    if (res.data.data==true){
                        alert("修改成功！");
                        location.href="director-list.html";
                    }else {
                        alert("修改失败，请联系管理员！");
                    }
                }else if (res.data.code==500){
                    location.href="500.html";
                }

            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("请先登录!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        positionInfo(){
            axios({
                url:"yly-api/admin/queryPosition",
                method:"get",
                headers: {"url":window.location.pathname,"token":localStorage.token}
            }).then(function (res) {
                console.log(res.data);
                if (res.data.code==200){
                    app.positions=res.data.data;
                }else if (res.data.code==500){
                    location.href="500.html";
                }
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("权限不足，请先登录!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        getvaluemethod(event){
            console.log(event.target.value);
            this.positionId=event.target.value;
        },

    }
});
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //r是一个数组
    if (r != null) return unescape(r[2]); return null;
}